<!--  input 单行输入框 - 属性面板 -->
<template>
  <div class="inputAttr">
    <div class="content">
      <div class="title">
        {{ attributeset.lab }}
      </div>
      <div v-if="attributeset.data" class="list">
        <div class="lab">字段标题：<span>最多30个字</span></div>
        <div>
          <input
            v-model="attributeset.data.title"
            type="text"
            max="10"
            placeholder="请输入"
          />
        </div>
        <div class="lab">占位文案：<span>最多30个字</span></div>
        <div>
          <input
            v-model="attributeset.data.placeholder"
            type="text"
            placeholder="请输入"
          />
        </div>
        <div class="fx-sb fx-al-ct">
          <div class="lab">表单宽度：</div>
          <div class="slider">
            <t-slider v-model="attributeset.data.width" size="small" />
          </div>
        </div>
        <div class="fx-sb fx-al-ct">
          <div class="lab">表单列数</div>
          <div>
            <t-radio-group
              v-model="attributeset.data.defaultWidth"
              default-value="1"
              size="small"
            >
              <t-radio-button value="1">一列</t-radio-button>
              <t-radio-button value="2">两列</t-radio-button>
              <t-radio-button value="3">三列</t-radio-button>
              <t-radio-button value="4">四列</t-radio-button>
            </t-radio-group>
          </div>
        </div>
        <div class="fx-sb fx-al-ct">
          <div class="lab">最少输入：</div>
          <div>
            <input
              v-model="attributeset.data.minLength"
              type="text"
              placeholder="请输入长度"
            />
          </div>
        </div>
        <div class="fx-sb fx-al-ct">
          <div class="lab">最多输入：</div>
          <div>
            <input
              v-model="attributeset.data.maxLength"
              type="text"
              placeholder="请输入长度"
            />
          </div>
        </div>
        <div class="fx-sb fx-al-ct">
          <div class="lab">是否只读</div>
          <div><t-switch v-model="attributeset.data.isReadOnly" /></div>
        </div>
        <div class="fx-sb fx-al-ct">
          <div class="lab">显示标题</div>
          <div><t-switch v-model="attributeset.data.isShowTitle" /></div>
        </div>
        <div class="fx-sb fx-al-ct">
          <div class="lab">输入统计</div>
          <div><t-switch v-model="attributeset.data.isStatistics" /></div>
        </div>
        <div class="fx-sb fx-al-ct">
          <div class="lab">是否必填</div>
          <div><t-switch v-model="attributeset.data.isMust" /></div>
        </div>
        <div class="fx-sb fx-al-ct">
          <div class="lab">唯一值</div>
          <div><t-switch v-model="attributeset.data.isOnly" /></div>
        </div>
        <div class="fx-sb fx-al-ct">
          <div class="lab">反馈类型</div>
          <div>
            <t-select size="small">
              <t-option
                v-for="item in options"
                :key="item.key"
                :label="item.value"
                :value="item.key"
              />
            </t-select>
          </div>
        </div>
        <div class="fx-sb fx-al-ct">
          <div class="lab">默认值</div>
          <div>
            <input
              v-model="attributeset.data.defaultValue"
              type="text"
              placeholder="请输入默认值"
            />
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script setup lang="ts">
import { ref, reactive, watch } from 'vue'

const props = defineProps({
  arrtData: Object
})

let attributeset = reactive({ ...props.arrtData })
const options = ref([
  {
    key: 'none',
    value: '无效验'
  },
  {
    key: 'number',
    value: '数字'
  },
  {
    key: 'int',
    value: '整数'
  },
  {
    key: 'float',
    value: '小数'
  },
  {
    key: 'url',
    value: 'URL地址'
  },
  {
    key: 'emil',
    value: '邮箱地址'
  },
  {
    key: 'phone',
    value: '手机号'
  },
  {
    id: 'idNumber',
    value: '身份证号'
  }
])
// 接收父级的方法
const emit: Function = defineEmits(['changeAttrHandle'])
// 同步调整attributeset
watch(
  () => props.arrtData,
  (val) => {
    attributeset = { ...val }
  },
  { deep: true }
)
// 监听整个表单的输入
watch(
  () => attributeset,
  (val) => {
    emit('changeAttrHandle', val)
  },
  { deep: true }
)
</script>
<style src="../../index.less" scoped></style>
<style lang="less" scoped>
.inputAttr {
}
</style>
